<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title>{$activity_info['jsonstr']['pageTitle']}</title>
    <link rel="stylesheet" type="text/css" href="{$Think.config.RESOURCEURL}wx_assets/luckydraw/css/index.css{$Think.config.RESOURCE_VER}" />
    <script src="{$Think.config.RESOURCEURL}wx_assets/luckydraw/js/remApp.js" type="text/javascript" charset="utf-8"></script>
   
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/layer.m.js" type="text/javascript" charset="utf-8"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/common.js{$Think.config.RESOURCE_VER}" type="text/javascript" charset="utf-8"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js" type="text/javascript" charset="utf-8"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/womenday/js/wx_share.js{$Think.config.RESOURCE_VER}" type="text/javascript" charset="utf-8"></script>
</head>
<style>
    .luckydrawContainer
    {
        background: url({$activity_info.jsonstr.luckydrawBackground.src}) no-repeat;
        background-size:cover;
        background-position: 50% 50%;
    }
</style>
<script type="text/javascript">
    var actId=$.util.getParamByObject("actId"),
    chanelId=$.util.getParamByObject("chanelId"),
    partake_id="{$record_info['partake_id']?$record_info['partake_id']:$record_info['partakeId']}",
    customerId=$.util.getParam("customerId"),
    fromUserId=$.util.getParam("fromUserId"),
    fromUserIdstr=fromUserId?"&fromUserId="+fromUserId:"",
    params={actId:actId,chanelId:(chanelId?chanelId:""),partake_id:partake_id?partake_id:""},
    geturl=function(method,bool){
        if(!method)method="index";
        if(bool&&!fromUserId)
        fromUserIdstr="&fromUserId={$userId?$userId:$record_info['userId']}";
        return "call.html?module=luckydraw&method="+method+fromUserIdstr+"&customerId="+customerId+"&params="+encodeURIComponent(JSON.stringify(params))
    },
    sharelink=geturl("index",1);
</script>
<script type="text/javascript">
    //是否参加过
    var code = "{$code}";
    //是否填写过
    var gain_status="{$record_info.gain_status}";
    //是否抽中
    var type="{$record_info.item_info.type}";

    //参加过并且填写过 跳转show页面，或者没抽中
    if((code !=='0' && gain_status === '1')||type === '4')
    window.location.href=geturl("show");    
    
</script>
<body>
<div class="luckydrawContainer">
<img id="ruleIMG" src="{$activity_info.jsonstr.ruleInfo.src}" alt="" style="display:none;">
<input type="hidden" id="closebtn" value="{$Think.config.RESOURCEURL}wx_assets/luckydraw/img/closebtn.png">
<div class="bigbg">
	<img src="{$record_info['item_info']['small_icon']}" alt="" >
    <img src="{$activity_info['jsonstr']['receiveLopeBackground']['src']}" alt="" >
	<div class="inputs" style="margin-top:1.2rem;">
        <volist name="activity_info['jsonstr']['mustWriteOptions']" id="value">
            <if condition="$value.selected eq 1">
                <if condition="$value.src">
                <img src="{$value.src}" alt="">
                <else />
                <p>{$value.name}</p>
                </if>
                <div style="margin:.8rem 0;">
                    <if condition="$value.name eq '姓名'">
                    <input data-type="write-real_name" type="text" placeholder="请输入您的真实姓名">
                    <elseif condition="$value.name eq '身份证'" />
                    <input data-type="write-id_card" type="text" placeholder="请输入您的身份证号码">
                    <else/>
                    <input data-type="write-telephone" type="text" placeholder="请输入您的手机号码">
                    </if>
                </div>
            </if>
        </volist>
	</div>
	<div class="btn">
		<a class="grabbtn" href="javascript:;">
			<img src="{$activity_info.jsonstr.receiveLopeBtn.src}" alt="">
		</a>
		<a class="rulebtn" href="javascript:;">
			<img src="{$activity_info.jsonstr.ruleInfoBtn.src}" alt="">
		</a>
	</div>
</div>
</div>
</body>
<script src="{$Think.config.RESOURCEURL}wx_assets/luckydraw/js/index.js{$Think.config.RESOURCE_VER}" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var baseUrl = '{$Think.config.SERVER_HOST}';
var shareData = {
        "title": "{$activity_info.title}",
        "desc": "{$activity_info.description}",
        "link": baseUrl+sharelink,
        "imgUrl": "{$activity_info.picurl}",
        "pkg": {
            "appId": '{$pkg.appId}',
            "timestamp": {$pkg['timestamp']?$pkg['timestamp']:'""'},
            "nonceStr": '{$pkg.nonceStr}',
            "signature": '{$pkg.signature}'
        }
    }
$(function() {
    wx_share.init(shareData);

    $(".grabbtn").on("click",function(){
        var bool=true,formdata={};
        $("[data-type^=write-]").each(function(){
            var value=$(this).val(),
                text=$(this).attr('placeholder'),
                name=$(this).data("type").split("-")[1];
            if(!value)
            {
                bool=false;
                layer.open({
                    content:text
                });

                return false;
            }
            else
            formdata[name]=value;
            
        })

        if(bool)
        {
            var _params={
                    actId:actId,
                    chanelId:chanelId,
                    partake_id:partake_id,
                    fromUserId:fromUserId
            };
            $.extend(true,_params,formdata);
            var link="call.json?module=luckydraw&method=update_record&customerId="+customerId+"&params="+JSON.stringify(_params);
            $.ajax({
                url:link,
                type:"GET",
                dataType:"json",
                beforeSend:function(){
                    layer.open({
                        type: 2,
                        content: '提交表单'
                    });
                },
                success:function(data){
                   layer.closeAll();
                   if(data.code)
                   window.location.href=geturl("show");
                   else
                   alert(data.info);
                }
            })
        }
    })
})
</script>

</html>
